package com.team5101.service.impl;


import com.team5101.config.DriudPoolUtil;
import com.team5101.pojo.Resume;
import com.team5101.service.IResumeService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Service;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.util.ArrayList;
import java.util.List;

@Service
public class ResumeServiceImpl implements IResumeService {

	private Logger logger = LoggerFactory.getLogger(ResumeServiceImpl.class);

	@Override
	public List<Resume> queryResumes() {
		Connection conn = null;
		PreparedStatement ps = null;
		ResultSet rs = null;

		ArrayList<Resume> resumes = new ArrayList<>();
		try {
			conn = DriudPoolUtil.getConn();
			String sql = "select * from tb_resume";
			ps = conn.prepareStatement(sql);
			rs = ps.executeQuery();
			logger.info("sql: {},结果：{}", sql, rs);
			while (rs.next()) {
				long id = rs.getLong("id");
				String address = rs.getString("address");
				String name = rs.getString("name");
				String phone = rs.getString("phone");
				Resume resume = new Resume(id, address, name, phone);
				resumes.add(resume);
			}
			return resumes;
		} catch (Exception e) {
			e.printStackTrace();
			return new ArrayList<>();
		} finally {
			//关闭链接
			DriudPoolUtil.close(conn, ps, rs);
		}
	}


}
